﻿/*
 * 1. 完成技术级别于职级待遇的映射变换
 * 2. 更合理的方式通过xml进行配置
 * 3. 增加容错处理
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HousingDistribution
{
    class RankMapping
    {
        public static RankMapping Instance()
        {
            if (instance == null)
                instance = new RankMapping();

            return instance;
        }

        public string GetGradeByTechRank(string techRank, string title)
        {
            if (techRank == null || title == null)
                return null;

            string specialTechRank = "技7";
            
            foreach (TechRank_DutyRandMapping e in RankMapping.mappingTable)
            {
                if (e.techRank.Equals(techRank))
                {
                    //非特殊技术级，直接返回
                    if (techRank != specialTechRank)
                        return e.grade;
                    else
                    {
                        if (IsHighTechTitle(title))
                            return "副师";
                        else
                            return "正团";
                    }
                }
            }

            return null;
        }

        private void InitMappingTable()
        {
            TechRank_DutyRandMapping elem;
            elem.techRank = "技13";
            elem.grade = "副连";
            elem.techRankRistrict = "";
            mappingTable.Add(elem);

            TechRank_DutyRandMapping elem0;
            elem0.techRank = "技12";
            elem0.grade = "正连";
            elem0.techRankRistrict = "";
            mappingTable.Add(elem0);

            TechRank_DutyRandMapping elem1;
            elem1.techRank = "技11";
            elem1.grade = "副营";
            elem1.techRankRistrict = "";
            mappingTable.Add(elem1);

            TechRank_DutyRandMapping elem2;
            elem2.techRank = "技10";
            elem2.grade = "正营";
            elem2.techRankRistrict = "";
            mappingTable.Add(elem2);

            TechRank_DutyRandMapping elem3;
            elem3.techRank = "技9";
            elem3.grade = "副团";
            elem3.techRankRistrict = "";
            mappingTable.Add(elem3);

            TechRank_DutyRandMapping elem4;
            elem4.techRank = "技8";
            elem4.grade = "正团";
            elem4.techRankRistrict = "";
            mappingTable.Add(elem4);

            TechRank_DutyRandMapping elem5;
            elem5.techRank = "技7";
            elem5.grade = "正团";
            elem5.techRankRistrict = "非高级职称";
            mappingTable.Add(elem5);

            TechRank_DutyRandMapping elem6;
            elem6.techRank = "技7";
            elem6.grade = "副师";
            elem6.techRankRistrict = "高级职称";
            mappingTable.Add(elem6);

            TechRank_DutyRandMapping elem7;
            elem7.techRank = "技6";
            elem7.grade = "副师";
            elem7.techRankRistrict = "";
            mappingTable.Add(elem7);

            TechRank_DutyRandMapping elem8;
            elem8.techRank = "技5";
            elem8.grade = "正师";
            elem8.techRankRistrict = "";
            mappingTable.Add(elem8);

            TechRank_DutyRandMapping elem9;
            elem9.techRank = "技4";
            elem9.grade = "正师";
            elem9.techRankRistrict = "";
            mappingTable.Add(elem9);

            TechRank_DutyRandMapping elem10;
            elem10.techRank = "技3";
            elem10.grade = "副军";
            elem10.techRankRistrict = "";
            mappingTable.Add(elem10);

            TechRank_DutyRandMapping elem11;
            elem11.techRank = "技2";
            elem11.grade = "正军";
            elem11.techRankRistrict = "";
            mappingTable.Add(elem11);

            TechRank_DutyRandMapping elem12;
            elem12.techRank = "技1";
            elem12.grade = "正军";
            elem12.techRankRistrict = "";
            mappingTable.Add(elem12);

            TechRank_DutyRandMapping elem13;
            elem13.techRank = "技12";
            elem13.grade = "一级科员";
            elem13.techRankRistrict = "";
            mappingTable.Add(elem13);

            TechRank_DutyRandMapping elem14;
            elem14.techRank = "技10";
            elem14.grade = "正科";
            elem14.techRankRistrict = "";
            mappingTable.Add(elem14);

        }

        //处理职称
        private bool IsHighTechTitle(string title)
        {
            string[] highTitleTable = DataDictionary.Instance().ArmmanHighTechTitle();
            foreach (string e in highTitleTable)
            {
                if (e.Equals(title))
                    return true;
            }

            string[] midTitleTable = DataDictionary.Instance().ArmmanMidTechTitle();
            foreach (string e in midTitleTable)
            {
                if (e.Equals(title))
                    return false;
            }

            return false;
        }
 
        //技术级别，技术职称，级别映射关系描述
        private struct TechRank_DutyRandMapping
        {
            public string techRank;
            public string grade;
            public string techRankRistrict;
        }
       
        private RankMapping()
        {
            InitMappingTable();
        }

        private static RankMapping instance = null;
        private static List<TechRank_DutyRandMapping> mappingTable = new  List<TechRank_DutyRandMapping>();
    }
}
